package com.test.test;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.*;
import java.util.HashMap;
import java.util.List;

@SpringBootTest
class ESTestApp {

    @Test
    void contextLoads() {

    }

    @Test
    void test1() {
        DasElasticsearchAutoConfiguration dasElasticsearchAutoConfiguration = new DasElasticsearchAutoConfiguration();

        ElasticsearchClient elastic = null;
        try {
            //1.获取client
            elastic = dasElasticsearchAutoConfiguration.elasticsearchClient("elastic",
                    "Byzk@1234", "192.168.12.114:9200");
            //2.查询数据
//            for (String table : tables) {
//                List<HashMap<String, String>> recordsMap = null;
//
//            }
            SearchResponse<Object> response = elastic.search(s -> s
                    .index("byzk_ds_dasm_classification_grading_field")
                    .query(q->q.bool(b->b.filter(f->f.matchAll(QueryBuilders.matchAll().build())))), Object.class);
            List<Hit<Object>> hits = response.hits().hits();
            //关闭连接
            elastic.shutdown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
